﻿
using System;
using UnityEngine;

//npc类型，和配置表里面的数据一一对应
public enum eNpcType 
{ 
    Function =1,
    Monster=2,
}


public class Npc : Creature
{
    NpcAI _ai;
    public override void Init(CreateSenceCreature serverData, CreatureDatabase tableData)
    {
        base.Init(serverData, tableData);

        transform.position = serverData.Pos;
        //_skillMgr.Init(this);
        CheckAndInitAI();

    }

    private void CheckAndInitAI()
    {
        if (!IsFuncNPC)
        {
            //_ai = new NpcAI();
            //_ai.Init(this);
        }
    }

    public override bool CanBeAttack(Creature attacker)
    {
        if (!base.CanBeAttack(attacker)) { return false; };
        //攻击者必须时角色，才能打npc
        var roleAttacker = attacker as Role;
        if (roleAttacker == null) { return false; }
        return !IsFuncNPC;
    }
    public bool IsFuncNPC { get { return (TableData as NpcTablebase).NpcType ==(int)eNpcType.Function; } }
    protected override void onDie()
    {
        base.onDie();
        _ai = null;
    }
    protected override void OnResqawn()
    {
        base.OnResqawn();
        CheckAndInitAI();
    }
    protected override void Update()
    {
        base.Update();
        //只对怪物启动AI
        if (!IsFuncNPC)
        {
            if (_ai != null)
            {
                _ai.Loop();
            }
        }

    }
}
